<template>
  <div class="tab_container">
      <div class="tab_items">
          <div class="tab_item" v-for="(item, index) in tabItem" :key="index" @click="goto(item)">
              <div class="tab_item_img">
                  <img :src="item.icon_active" v-if="selPath === item.path" alt="">
                  <img :src="item.icon" v-else alt="">
              </div>
              <div :class="selPath === item.path?'tab_item_title_active':'tab_item_title'">{{item.title}}</div>
          </div>
          <span class="cart_length" v-show="this.cart.length > 0">{{this.cart.length}}</span>
      </div>
  </div>
</template>

<script>
import PATH from '../../router/constant'
export default {
    computed: {
        cart: function() {
            return this.$store.state.cart
        }
    },
    data() {
        return {
            selPath: '/',
            tabItem: [
                {
                    "title": "首页",
                    "icon": require("../../assets/tabIcon/shouye.png"),
                    "icon_active": require("../../assets/tabIcon_active/shouye.png"),
                    "path": PATH.HOME
                },
                {
                    "title": "分类",
                    "icon": require("../../assets/tabIcon/leimupinleifenleileibie.png"),
                    "icon_active": require("../../assets/tabIcon_active/leimupinleifenleileibie.png"),
                    "path": PATH.CLASSIFY
                },
                {
                    "title": "购物车",
                    "icon": require("../../assets/tabIcon/gouwuche.png"),
                    "icon_active": require("../../assets/tabIcon_active/gouwuche.png"),
                    "path": PATH.CART,
                },
                {
                    "title": "我的",
                    "icon": require("../../assets/tabIcon/wode.png"),
                    "icon_active": require("../../assets/tabIcon_active/wode.png"),
                    "path": PATH.MINE
                }
            ]
        }
    },
    methods: {
        goto(item) {
            this.selPath = item.path;
            this.$router.push(item.path)
        }
    }
}
</script>

<style>
.tab_container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1.1rem;
    background-color: #fff;
    border-top: 1px solid #eee;
}
.tab_items {
    height: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.tab_item_img {
    text-align: center;
}
.tab_item_title {
    font-size: 0.2rem;
    color: #333;
}
.tab_item_title_active {
    font-size: 0.2rem;
    color: red !important;
}
.cart_length {
    display: inline-block;
    width: 0.3rem;
    height: 0.3rem;
    border-radius: 0.3rem;
    font-size: 0.2rem;
    text-align: center;
    position: absolute;
    left: 4.8rem;
    bottom: 0.7rem;
    background-color: red;
    color: white;
}
</style>